<template>
  <div>

    <xdh-curd class="config-history" :mixin="historyMixin" name="history" :page-size="pageSize" :list-title="'历史关注'" :query.sync="query" :model="model" ref="tableCurd" :addable="false" :editable="false" :removable="false">
      <!-- 查询表单 -->
      <template slot="filter-items">
        <el-form-item prop="keyword">
          <el-input placeholder="关键字" v-model="query.keyword"></el-input>
        </el-form-item>
      </template>
      <template slot="table-tool">

        <el-button type="primary" size="mini" icon="el-icon-plus" @click="focusBath">批量关注</el-button>

      </template>
      <!-- 显示列表 -->
      <template slot="table-columns" slot-scope="scope">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="ID" prop="id"></el-table-column>
        <el-table-column label="姓名" prop="name"></el-table-column>
        <el-table-column label="国籍" prop="country"></el-table-column>
        <el-table-column label="性别" prop="sex"></el-table-column>
        <el-table-column label="出生日期" prop="birthday"></el-table-column>
        <el-table-column label="创建日期" prop="createTime"></el-table-column>
        <el-table-column label="删除日期" prop="deleteTime"></el-table-column>
        <el-table-column label="删除人" prop="deletor"></el-table-column>
      </template>
      <!-- 操作按钮-->
      <template slot="table-handle-column" slot-scope="scope">
        <el-button size="mini" @click="view(scope.row, scope.$index)">查看
        </el-button>
        <el-button size="mini" @click="handleFocus(scope.row, scope.$index)">关注
        </el-button>
      </template>
    </xdh-curd>
    <option-select-dialog ref="groupOption"></option-select-dialog>
  </div>
</template>
<script>
  import XdhCurd from '@/widgets/xdh-curd';
  import historyMixin from '@/base/mixin/history';
  import focusMixin from '@/base/mixin/focus';
  import optionSelectDialog from '@/components/focusManage/optionSelectDialog';
  export default {
    mixins: [focusMixin],
    components: {
      XdhCurd,
      optionSelectDialog
    },
    data() {
      return {
        pageSize: 99,
        query: {
          keyword: ''
        },
        model: {
          name: '',
          title: '',
          id: 'fdsaf'
        },
        historyMixin: historyMixin
      };
    },
    methods: {
      handleOpenAdd() {
        this.$refs.tableCurd.dialogMode = 'insert';
        this.$refs.tableCurd.currentModel = { ...this.$refs.tableCurd.model };
        this.$refs.tableCurd.dialogClosed = false;
      },
      focusBath() {
        let selection = this.$refs.tableCurd.selection;
        if (selection.length > 0) {
          this.$refs.groupOption
            .getOption()
            .then(res => {
              // focus 操作
              this.focusPerson({
                id: selection.map(r => r.pkValue).join(','),
                groupId: res.group
              }).then(res => {
                if (res) {
                  this.$message({
                    type: 'success',
                    message: '批量关注成功'
                  });
                }
              });
            })
            .catch(e => {});
        } else {
          this.$message({
            type: 'warning',
            message: '请至少勾选一条数据！'
          });
        }
      },
      handleFocus(row, index) {
        this.$refs.groupOption
          .getOption()
          .then(res => {
            // focus 操作
            this.focusPerson({
              id: row.pkValue,
              groupId: res.group
            }).then(res => {
              if (res) {
                this.$message({
                  type: 'success',
                  message: '关注成功'
                });
              }
            });
          })
          .catch(e => {});
      },
      view(row, index) {
        this.$router.push('/focus-manage/person-detail/focus/' + this.model.id);
      }
    }
  };
</script>
<style  type="text/scss" lang="scss" scoped>
</style>